#
package Validate;

# Validate.pm
# A module that contains field validation routines.
# This is mainly used for derived packages, and provides a handy
# set of "default" actions.
#
# The public interface is:
# val = Validate->new(dbname) - initialize routines for checking entries
#                         for that DB
# val -> help(field) - return helptext for field
# val -> check(field, value) - return error text, or 0 for "ok"
# val -> clean(record) - return a "cleaned" record of that type
#
# IMPLEMENTATION:
# Very little - this file is a fallback.

sub new {
   my $class = shift;
   my $dbname = shift;
   my $self = [];

   bless $self, $class;
   $self;
}

sub help {
   my ($self, $field) = @_;
   return "";
}

sub check {
    my ($self, $field, $value) = @_;
   return "";
}

sub cleanfield {
    my ($self, $field, $value) = @_;
    return $value;
}

sub clean {
    my ($self, $rec) = @_;
    my $value = {};
    for $field (keys(%$rec)) {
	# Skip reserved fields
	if ($field !~ /^\*/) {
	    $$value{$field} = $self->cleanfield($field, $$rec{$field});
	}
    }
   return $value;
}

1;
